﻿using System;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace CDTM.Modules.DANHMUC.HOME
{
    public enum ModulePages
    {
        ItemManager
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = Guid.Empty.ToString();
            itemSetting.Name = "ModuleID của Module";
            itemSetting.Description = "ModuleID của Module muốn sử dụng";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("MODE.ModuleID", itemSetting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/CDTM.Modules.DANHMUC.HOME/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page = ModulePages.ItemManager;
            if (pageName != null)
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), pageName, true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Guid modeID = new Guid(this.Settings["MODE.ModuleID"].ToString());

            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditItem", "modeid={0}", modeID);

            this.LoadChildControl();
        }
    }
}